/*
给n个数创建双向循环链表，找到其中的数x,删除x前面的元素和后面的元素，
如果没有x,则不进行任何操作，最后正向输出链表内容。
*/
#include<bits/stdc++.h>
using namespace std;
struct LNode{
    int data;
    LNode *pre;
    LNode *next;
};
int main(){
    int n, x;
    cin >> n >> x;
    LNode *h = new LNode;
    LNode *t = h;
    for(int i = 1; i <= n; ++i){
        LNode *p = new LNode;
        cin >> p->data;
        t->next = p;
        p->pre = t;
        t = p;
    }
    t->next = h->next;
    h->next->pre = t;

    LNode *cur = h->next;
    do{
        if(cur->data == x && cur->next != cur){
            LNode *curPre = cur->pre;
            LNode *prePre = curPre->pre;
            LNode *curNext = cur->next;
            LNode *nextNext = curNext->next;
            if(h->next == curPre) h->next = cur;
            else if(h->next == curNext) h->next = curNext->next;

            prePre->next = cur;
            cur->pre = prePre;
            cur->next = nextNext;
            nextNext->pre = cur;
            delete curPre;
            delete curNext;
        }
        cur = cur->next;
    }while(cur != h->next);
    do{
        cout << cur->data << " ";
        cur = cur->next;
    }while(cur != h->next);
    return 0;
}

